import wepy from "@wepy/core";
import baseToast from "./baseToast"
wepy.get = function(url, data) {
  wx.showLoading({
    title: '拼命加载中...'
  })
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'https://www.uinav.com/api/public/v1' + url,
      data: data,
      success:(res) => {
        let { message, meta } = res.data
        if(meta.status === 200) {
          resolve(message)
        } else {
          baseToast(meta.msg)
        }
      },

      fail:(err) => {
        reject(err)
      },

      complete() {
        wx.hideLoading()
      }
    })
  })
}
wepy.post = function(url, data) {
  wx.showLoading({
    title: '拼命加载中...'
  })
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'https://www.uinav.com/api/public/v1' + url,
      data: data,
      method: 'post',
      success:(res) => {
        let { message, meta } = res.data
        if(meta.status === 200) {
          resolve(message)
        } else {
          baseToast(meta.msg)
        }
      },

      fail:(err) => {
        reject(err)
      },

      complete() {
        wx.hideLoading()
      }
    })
  })
}